package com.m3958.firstgwt.server.utils;

import java.util.LinkedHashMap;
import java.util.Map;

public class ServerKeyValueCombine {
	private Map<String, String> lm = new LinkedHashMap<String, String>();
	
	
	public ServerKeyValueCombine(String keyvalueStr){
		decodeToKeyValues(keyvalueStr);
	}
	
	
	private void decodeToKeyValues(String keyvalueStr2) {
		String[] ss = keyvalueStr2.split(",",2);
		String[] sss = ss[1].split(ss[0]);
		int l = sss.length;
		if(sss.length % 2 != 0){
			l--;
		}
		for(int i=0;i<l;i++){
			lm.put(sss[i], sss[++i]);
		}
	}


	public void putPair(String key,String value){
		if(value == null)value = "";
		lm.put(key, value);
	}
	
	
	public String getStringValue(String key){
		return lm.get(key);
	}
	
	public int getIntValue(String key){
		String v = lm.get(key);
		if(v != null){
			try {
				return Integer.parseInt(v);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
		return 0;
	}
	

}
